package com.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.demo.entity.ChannelEntity;
import com.demo.entity.MdataBaseParamBo;
import com.demo.service.ChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 渠道
 *
 * @author liuyuanqi
 * @date 2021/6/21
 */
@RestController
@RequestMapping("/channel")
@Slf4j
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    /**
     * 保存渠道信息
     *
     * @return 默认返回
     */
    @PostMapping("/save")
    public Object save(@RequestBody List<MdataBaseParamBo> list) {
        channelService.sync(list);
        return ResultJson.ok(0);
    }

    /**
     * 获取渠道信息
     *
     * @return 默认返回
     */
    @PostMapping("/list")
    public Object list() {
        List datas = channelService.list();
        return ResultJson.ok(
                new ArrayList() {{
                    add(MdataBaseParamBo.builder().mdataCode("tecode").mdataName("主数据测试").parentMdataCode("")
                            .jsonDatas(JSONObject.toJSONString(new ArrayList(){{
                                add(new HashMap(){{
                                    put("d1", "d11");
                                }});
                                add(new HashMap(){{
                                    put("d2", "d22");
                                    put("d3", "d3");
                                }});
                            }}))
                            .build());
                }}
        );
    }

}
